﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
  public class EmailBLL
  {
    public List<Email> GetAll()
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.Emails.OrderByDescending(p => p.Id).ToList();
      }
    }
    public bool isExits(string email)
    {
      using (var data= new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        Email obj = data.Emails.Where(p => p.Email1 == email).FirstOrDefault();
        return (obj == null ? false : true);
      }
    }
    public void Add(Email obj)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        data.Emails.InsertOnSubmit(obj);
        data.SubmitChanges();
      }
    }
    public void Delete(int id)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        Email email = data.Emails.Where(p => p.Id == id).FirstOrDefault();
        if (email != null)
        {
          data.Emails.DeleteOnSubmit(email);
          data.SubmitChanges();
        }
      }
    }
  }
}
